package common.qzone.view
{
	import com.common.utils.Reflection;
	import com.greensock.TweenLite;
	import com.liangzhong.message.http.JsClient;
	
	import common.qzone.IQzoneRightView;
	
	import flash.display.Loader;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	import lz.controls.core.UIComponent;

	/**
	 *黄钻特权界面 
	 * @author lake
	 * 
	 */	
	public class QzoneRightView extends UIComponent implements IQzoneRightView
	{
		private var loader 		:Loader;//加载器
		/**
		 * 关闭
		 */		
		private var closeBtn 			:SimpleButton;
		/**
		 * 开通年费黄钻
		 */		
		private var openYearQzoneBtn 	:SimpleButton;
		/**
		 * 开通黄钻
		 */		
		private var openQzoneBtn		:SimpleButton;
		
		public function QzoneRightView()
		{
			super();
		}
		
		public function set data(value:*):void
		{
			if(_symbolSkin)
			{
				_symbolSkin.gotoAndPlay(1);
			}
		}
		
		public function get data():*
		{
			return null;
		}
		/**
		 *初始化 
		 * @param view
		 * 
		 */	
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.lz.res.QzoneRightPanel");
			if(_symbolSkin)
			{
				config();
			}
			else
			{
				var url :String = "res/swf/plugin/qzone_vip.swf";
				loader = new Loader();
				loader.load(new URLRequest(url),new LoaderContext(false,ApplicationDomain.currentDomain));
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleteHandler);
				loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loaderErrorHandler);
			}
		}
		/**
		 *配置界面 
		 * 
		 */	
		private function config():void
		{
			this.addChild(_symbolSkin);
			_symbolSkin.gotoAndPlay(1);
			_symbolSkin.x = 120;
			_symbolSkin.y = 100;
			closeBtn = _symbolSkin.mc.closeBtn;
			openYearQzoneBtn = _symbolSkin.mc.openYearQzoneBtn;
			openQzoneBtn = _symbolSkin.mc.openQzoneBtn;
			addEvtListener();
		}
		/**
		 * 添加事件 
		 * 
		 */	
		public function addEvtListener():void
		{
			closeBtn.addEventListener(MouseEvent.CLICK,onCloseHandler);
			openQzoneBtn.addEventListener(MouseEvent.CLICK,openHuangHandler);
			openYearQzoneBtn.addEventListener(MouseEvent.CLICK,openHuangHandler);
		}
		/**
		 * onCloseHandler
		 * @param e
		 * 
		 */		
		private function onCloseHandler(e :MouseEvent):void
		{
			destroyView();
		}
		/**
		 *开通黄砖 
		 * @param e
		 * 
		 */		
		private function openHuangHandler(e :MouseEvent):void
		{
			switch(e.target)
			{
				case openQzoneBtn:
				{
					JsClient.app_tobemember(1);
					break;
				}
				case openYearQzoneBtn:
				{
					JsClient.app_tobemember(2);
					break;
				}
			}
		}
		/**
		 * loaderErrorHandler
		 * @param e
		 * 
		 */		
		private function loaderErrorHandler(e :Event):void
		{
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loadCompleteHandler);
			loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,loaderErrorHandler);
			loader = null;
		}
		/**
		 * 
		 * 加载完毕
		 */		
		private function loadCompleteHandler(e :Event):void
		{
			_symbolSkin = Reflection.createInstance("com.lz.res.QzoneRightPanel");
			if(_symbolSkin)
			{
				config();
			}
			else
			{
				destroyView();
			}
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loadCompleteHandler);
			loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,loaderErrorHandler);
			loader = null;
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
			closeBtn.removeEventListener(MouseEvent.CLICK,onCloseHandler);
			openQzoneBtn.removeEventListener(MouseEvent.CLICK,openHuangHandler);
			openYearQzoneBtn.removeEventListener(MouseEvent.CLICK,openHuangHandler);
		}
		/**
		 * 销毁
		 * 
		 */	
		public function destroyView():void
		{
			//removeEvtListener();
			TweenLite.to(this,.3,{alpha:0,onComplete:fadeOutComplete});
		}
		/**
		 *消失 
		 * 
		 */		
		override protected function fadeOutComplete():void
		{
			this.alpha = 1;
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
		}
	}
}